local skill = fk.CreateSkill{
  name = "tea__anjing"
}
---@type TrigSkelSpec<TrigFunc>
local anjing = {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or player.dead then return end
    if event == fk.RoundStart then
      return player:getMark("@anjing_attackrange") < 5
    else
      return not table.every(player.room.alive_players, function(p)
        return p:getMark("anjing_record-phase") == p:getAttackRange()
      end)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.RoundStart then
      return true
    else
      local room = player.room
      local card = Fk:cloneCard("slash")
      if not player:prohibitUse(card) then
        local use = room:askToUseCard(player, {
          skill_name = self.name,
          name = "slash",
          prompt = "#anjing-ask",
          pattern = "slash",
          extra_data = {
            bypass_times = true,
          }
        })
        if use then
          self.cost_data = use 
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.RoundStart then
      player.room:addPlayerMark(player, "@anjing_attackrange", 1)
    else
      player.room:useCard(self.cost_data)
    end
  end,
}
---@type TrigSkelSpec<TrigFunc>
local anjing_refresh = {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and not player.dead
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      room:setPlayerMark(p, "anjing_record-phase", p:getAttackRange())
    end
  end,
}
---@type AttackRangeSpec
local anjing_attackrange = {
  correct_func = function (self, from, to)
    return from:getMark("@anjing_attackrange")
  end,
}
skill:addEffect(fk.RoundStart, anjing)
skill:addEffect(fk.EventPhaseEnd, anjing)
skill:addEffect(fk.EventPhaseStart, anjing_refresh)
skill:addEffect("atkrange", anjing_attackrange)
return skill